<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <canvas width="512" height="512"></canvas>
  <script src="/js/mesh.js"></script>
  <script>
const url = 'https://p0.ssl.qhimg.com/t01a72262146b87165f.png';

const {Renderer, Figure2D, Mesh2D} = meshjs;

const canvas = document.querySelector('canvas');
const renderer = new Renderer(canvas, {
  // contextType: '2d',
});

(async function () {
  const texture = await renderer.loadTexture(url);
  const figure = new Figure2D();
  figure.rect(0, 0, 196, 256);
  const mesh = new Mesh2D(figure);
  mesh.setFill({
    color: 'red',
  });
  mesh.setTexture(texture, {
    srcRect: [50, 50, 146, 128],
    rect: [0, 50, 50, 150],
    rotated: true,
    // repeat: true,
  });

  const mesh2 = new Mesh2D(figure, canvas);
  // mesh2.rotate(0.7);
  setTimeout(() => {
    console.log(111);
    mesh2.setTexture(texture, {

    });
    renderer.drawMeshes([mesh, mesh2]);
  }, 500);

  mesh.translate(202, 22); // 300 - 196 / 2, 150 - 256 / 2
  window.mesh = mesh;
  window.mesh2 = mesh2;
  window.texture = texture;

  renderer.drawMeshes([mesh, mesh2]);
}());
  </script>
</body>
</html>